﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace JSM.Internal
{
	/// <summary>
	/// Container for javascript functions
	/// </summary>
	internal class JavaScriptFunctionContainer
	{
		/// <summary>
		/// Constructor for the javascript functions container
		/// </summary>
		/// <param name="function">
		/// Name of the function as string.
		/// </param>
		/// <param name="functionParameters">
		/// Parameters to pass to the function.
		/// </param>
		internal JavaScriptFunctionContainer(string function, IList<object> functionParameters)
		{
			// Check if the function is a valid function name.
			if (Regex.IsMatch(function, @"[^a-zA-Z0-9.]+", RegexOptions.Compiled | RegexOptions.CultureInvariant))
				throw new ArgumentException(string.Format("The given function '{0}' is not a valid function name.", function));
			Function = function;
			Parameters = functionParameters;
		}

		/// <summary>
		/// The function as string.
		/// </summary>
		public string Function { get; private set; }

		/// <summary>
		/// The parameters to pass to the function.
		/// </summary>
		public IList<object> Parameters { get; private set; }
	}
}